﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Graphics;
using Terraria.UI;

namespace Terraria.GameContent.UI.Elements
{
	// Token: 0x020003FE RID: 1022
	public class UITextPanel<T> : UIPanel
	{
		// Token: 0x1700028D RID: 653
		// (get) Token: 0x060023E7 RID: 9191 RVA: 0x0001966C File Offset: 0x0001786C
		public bool IsLarge
		{
			get
			{
				return this._isLarge;
			}
		}

		// Token: 0x1700028E RID: 654
		// (get) Token: 0x060023E8 RID: 9192 RVA: 0x00019674 File Offset: 0x00017874
		// (set) Token: 0x060023E9 RID: 9193 RVA: 0x0001967C File Offset: 0x0001787C
		public bool DrawPanel
		{
			get
			{
				return this._drawPanel;
			}
			set
			{
				this._drawPanel = value;
			}
		}

		// Token: 0x1700028F RID: 655
		// (get) Token: 0x060023EA RID: 9194 RVA: 0x00019685 File Offset: 0x00017885
		// (set) Token: 0x060023EB RID: 9195 RVA: 0x0001968D File Offset: 0x0001788D
		public float TextScale
		{
			get
			{
				return this._textScale;
			}
			set
			{
				this._textScale = value;
			}
		}

		// Token: 0x17000290 RID: 656
		// (get) Token: 0x060023EC RID: 9196 RVA: 0x00019696 File Offset: 0x00017896
		public Vector2 TextSize
		{
			get
			{
				return this._textSize;
			}
		}

		// Token: 0x17000291 RID: 657
		// (get) Token: 0x060023ED RID: 9197 RVA: 0x0001969E File Offset: 0x0001789E
		public string Text
		{
			get
			{
				if (this._text != null)
				{
					return this._text.ToString();
				}
				return "";
			}
		}

		// Token: 0x17000292 RID: 658
		// (get) Token: 0x060023EE RID: 9198 RVA: 0x000196C4 File Offset: 0x000178C4
		// (set) Token: 0x060023EF RID: 9199 RVA: 0x000196CC File Offset: 0x000178CC
		public Color TextColor
		{
			get
			{
				return this._color;
			}
			set
			{
				this._color = value;
			}
		}

		// Token: 0x060023F0 RID: 9200 RVA: 0x000196D5 File Offset: 0x000178D5
		public UITextPanel(T text, float textScale = 1f, bool large = false)
		{
			this.SetText(text, textScale, large);
		}

		// Token: 0x060023F1 RID: 9201 RVA: 0x0001970E File Offset: 0x0001790E
		public override void Recalculate()
		{
			this.SetText(this._text, this._textScale, this._isLarge);
			base.Recalculate();
		}

		// Token: 0x060023F2 RID: 9202 RVA: 0x0001972E File Offset: 0x0001792E
		public void SetText(T text)
		{
			this.SetText(text, this._textScale, this._isLarge);
		}

		// Token: 0x060023F3 RID: 9203 RVA: 0x0047ADC0 File Offset: 0x00478FC0
		public virtual void SetText(T text, float textScale, bool large)
		{
			DynamicSpriteFont dynamicSpriteFont = large ? Main.fontDeathText : Main.fontMouseText;
			Vector2 vector = new Vector2(dynamicSpriteFont.MeasureString(text.ToString()).X, large ? 32f : 16f) * textScale;
			this._text = text;
			this._textScale = textScale;
			this._textSize = vector;
			this._isLarge = large;
			this.MinWidth.Set(vector.X + this.PaddingLeft + this.PaddingRight, 0f);
			this.MinHeight.Set(vector.Y + this.PaddingTop + this.PaddingBottom, 0f);
		}

		// Token: 0x060023F4 RID: 9204 RVA: 0x0047AE74 File Offset: 0x00479074
		protected override void DrawSelf(SpriteBatch spriteBatch)
		{
			if (this._drawPanel)
			{
				base.DrawSelf(spriteBatch);
			}
			CalculatedStyle innerDimensions = base.GetInnerDimensions();
			Vector2 pos = innerDimensions.Position();
			if (this._isLarge)
			{
				pos.Y -= 10f * this._textScale * this._textScale;
			}
			else
			{
				pos.Y -= 2f * this._textScale;
			}
			pos.X += (innerDimensions.Width - this._textSize.X) * 0.5f;
			if (this._isLarge)
			{
				Utils.DrawBorderStringBig(spriteBatch, this.Text, pos, this._color, this._textScale, 0f, 0f, -1);
				return;
			}
			Utils.DrawBorderString(spriteBatch, this.Text, pos, this._color, this._textScale, 0f, 0f, -1);
		}

		// Token: 0x04004006 RID: 16390
		private T _text;

		// Token: 0x04004007 RID: 16391
		private float _textScale = 1f;

		// Token: 0x04004008 RID: 16392
		private Vector2 _textSize = Vector2.Zero;

		// Token: 0x04004009 RID: 16393
		private bool _isLarge;

		// Token: 0x0400400A RID: 16394
		private Color _color = Color.White;

		// Token: 0x0400400B RID: 16395
		private bool _drawPanel = true;
	}
}
